package com.ddxz.elastic.job;

import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.dataflow.DataflowJob;

import java.util.ArrayList;
import java.util.List;

/**
 * description
 *
 * @author 朱宗刚
 * @version 1.0.0
 * @date 2021/2/24
 */

public class DdxzDataFlowJob implements DataflowJob<Integer> {
    private static int count = 1;
    private static final int NUM = 5;
    @Override
    public List<Integer> fetchData(ShardingContext shardingContext) {
        List<Integer> rst = new ArrayList<>(NUM);
        for(int idx = count; idx < count + NUM; ++idx) {
            rst.add(idx);
        }
        ++count;
        return rst;
    }

    @Override
    public void processData(ShardingContext shardingContext, List<Integer> data) {
        int sum = 0;
        for(Integer item : data) {
            sum += item;
        }

        System.out.println("sum = "+ sum);
    }
}
